package com.thankcreate.model;

public abstract class Contact {
	
	private String name;				
	private String sex;	
	private int photoIndex;
	private Contact parent;
	
	public Contact(String name, String sex, int photoIndex, Contact parent) {
		super();
		this.name = name;
		this.sex = sex;
		this.photoIndex = photoIndex;
		this.parent = parent;
		if(parent instanceof ContactGroup){
			((ContactGroup)parent).addEntry(this);
		}
	}
	
	public void fireContactChanged(){
		if(getParent() != null){
			getParent().fireContactChanged();
		}else{
			if(this instanceof ContactGroup){
				ContactGroup contactGroup = (ContactGroup)this;
				if(contactGroup.getListeners() == null){
					return;
				}
				for (Object object : 
					contactGroup.getListeners().getListeners()) {
					IContactListener iContactListener = (IContactListener)object;
					iContactListener.contactsChanged();
				}
			}
		}
	}
	
	public abstract boolean isEmpty();
	
	public abstract void addListener(IContactListener contactListener);
	
	
	public Contact getParent() {
		return parent;
	}
	public void setParent(Contact parent) {
		this.parent = parent;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public int getPhotoIndex() {
		return photoIndex;
	}
	public void setPhotoIndex(int photoIndex) {
		this.photoIndex = photoIndex;
	}
	
	public abstract void addEntry(Contact ob);	
	public abstract void removeEntry(Contact ob);		
}
